package component.titan.custom.serializer;

import com.thinkaurelius.titan.core.attribute.AttributeSerializer;
import com.thinkaurelius.titan.diskstorage.ScanBuffer;
import com.thinkaurelius.titan.diskstorage.WriteBuffer;
import com.thinkaurelius.titan.graphdb.database.serialize.attribute.LongSerializer;
import org.joda.time.DateTime;

/**
 * Created by lovepocky on 16/7/5.
 */
public class JodaJavaSerializer implements AttributeSerializer<DateTime> {

    private LongSerializer serializer;

    public JodaJavaSerializer() {
        serializer = new LongSerializer();
    }

    @Override
    public DateTime read(ScanBuffer buffer) {
        return new DateTime(serializer.read(buffer));
    }

    @Override
    public void write(WriteBuffer buffer, DateTime attribute) {
        serializer.write(buffer, attribute.getMillis());
    }
}
